<template>
	<view class="business-order-detail" v-if="detail.id">
		<uni-nav-bar :fixed="true" :shadow="false" :statusBar="true" color="#fff"
			:backgroundColor="scrollTop < 20 ?``:primaryColor" leftIcon="icon-left" title="订单详情">
		</uni-nav-bar>
		<view :style="{height:`${configInfo.navBarHeight}px`}"></view>
		<image mode="aspectFill" lazy-load class="common-bg abs" src="https://lbqny.migugu.com/admin/farm/bg-cash.png">
		</image>
		<view class="pl-lg pr-lg c-base" style="height: 120rpx;">
			<view class="f-sm-title text-bold pt-md">{{statusType[detail.pay_type]}}</view>
		</view>
		<view class="order-text-info ml-md mr-md pd-lg fill-base f-paragraph c-title box-shadow radius-24"
			v-if="detail.send_type == 2">
			<view @tap.stop="toMap" class="flex-warp">
				<i class="iconfont icon-dingwei mr-sm" style="font-size: 28rpx;margin-top: 6rpx;"></i>
				<view class="flex-1">{{`${detail.address_info.address}${detail.address_info.address_info}`}}</view>
			</view>
			<view @tap.stop="$util.goUrl({url:detail.address_info.mobile,openType:'call'})"
				class="flex-y-baseline c-caption" style="margin:5rpx 0 0 38rpx;">{{detail.address_info.user_name}}
				<view class="ml-lg">
					{{detail.address_info.mobile}}
				</view>
			</view>
		</view>
		<view class="order-text-info mt-md ml-md mr-md pl-lg pr-lg fill-base f-paragraph c-title box-shadow radius-24">
			<view class="flex-between pt-lg pb-lg">
				<view class="text c-desc">{{detail.send_type == 1 ? '自提时间':'配送时间'}}</view>
				<view>{{detail.user_send_time}}</view>
			</view>
			<view class="pt-lg pb-lg b-1px-t" v-if="detail.text">
				<view class="text c-desc">备注</view>
				<view class="mt-sm">
					<text decode="emsp" style="word-break:break-all;">{{detail.text}}</text>
				</view>
			</view>
		</view>

		<view class="mt-md ml-md mr-md pd-lg fill-base f-paragraph c-title box-shadow radius-24">
			<view class="flex-y-center pb-lg b-1px-b">
				<i class="iconfont icon-dianpu mr-sm"></i>
				<view class="f-title c-title text-bold ellipsis">{{detail.store_info.title}}</view>
			</view>
			<view class="order-item flex-center" :class="[{'mt-lg':index==0},{'mt-md':index!=0}]"
				v-for="(item,index) in detail.order_goods" :key="index">
				<image mode="aspectFill" lazy-load class="avatar box-shadow-mini radius-24" :src="item.goods_cover">
				</image>
				<view class="flex-1 ml-lg">
					<view class="f-paragraph c-title text-bold max-490 ellipsis"> {{item.goods_name}}
					</view>
					<view class="f-caption c-title" :class="[{'flex-center':item.refund_num*1>0}]">
						<view class="ellipsis" :style="{maxWidth:item.refund_num*1>0?'300rpx':'490rpx'}">
							{{item.spe_name}}
						</view>
						<view class="flex-1 c-warning text-right" v-if="item.refund_num*1>0">已退x{{item.refund_num}}
						</view>
					</view>
					<view class="flex-y-baseline mt-sm">
						<view class="flex-1 f-paragraph c-warning">¥{{item.goods_price}} </view>
						<view class="f-caption c-caption">x {{item.goods_num}} </view>
					</view>
				</view>
			</view>
			<view class="mt-lg pt-lg pb-lg f-paragraph c-title b-1px-tb">
				<view class="flex-between">
					<view>商品金额</view>
					<view>¥{{detail.init_goods_price}}</view>
				</view>
				<block v-if="detail.send_type == 2">
					<view class="flex-between mt-sm">
						<view>配送费</view>
						<view>¥{{detail.freight}}</view>
					</view>
				</block>
				<view class="flex-between mt-sm" v-if="detail.kill_discount_price*1>0">
					<view>秒杀优惠</view>
					<view class="c-warning">-¥{{detail.kill_discount_price}}</view>
				</view>
				<view class="flex-between mt-sm" v-if="detail.integral_discount_price*1>0">
					<view>积分抵扣</view>
					<view class="c-warning">-¥{{detail.integral_discount_price}}</view>
				</view>
				<view class="flex-between mt-sm" v-if="detail.discount*1>0">
					<view>卡券优惠</view>
					<view class="c-warning">-¥{{detail.discount}}</view>
				</view>
			</view>
			<view class="mt-lg f-paragraph c-title flex-between mt-sm">
				<view>合计</view>
				<view class="f-title c-warning text-bold">¥{{detail.pay_price}}</view>
			</view>
		</view>

		<video class="item-video mt-md ml-md mr-md radius-24" :loop="false" enable-play-gesture enable-progress-gesture
			:src="detail.video" @timeupdate="onTimeUpdate" @waiting="onWaiting" @progress="onProgress"
			@loadedmetadata="onLoadedMetaData" v-if="detail.video">
		</video>

		<view class="order-text-info mt-md ml-md mr-md pd-lg fill-base f-caption c-title box-shadow radius-24">
			<view class="flex-warp pt-sm">
				<view class="text c-caption">订单编号</view>
				<view class="flex-1 flex-y-center">{{detail.order_code}}
					<view @tap="$util.goUrl( {url:`${detail.order_code}`,openType:'copy'})"
						class="copy-btn sm flex-center fill-body" :style="{color:primaryColor}">复制</view>
				</view>
			</view>
			<block v-if="detail.send_type == 2">
				<view class="flex-warp pt-md" v-if="detail.transaction_id">
					<view class="text c-caption">付款单号</view>
					<view class="flex-1 flex-y-center">{{detail.transaction_id}}
						<view @tap="$util.goUrl( {url:`${detail.transaction_id}`,openType:'copy'})"
							class="copy-btn sm flex-center fill-body" :style="{color:primaryColor}">复制</view>
					</view>
				</view>
				<view class="flex-warp pt-md" v-if="detail.pay_type == -1 && detail.refund_code">
					<view class="text c-caption">退款单号</view>
					<view class="flex-1 flex-y-center">{{detail.refund_code}}
						<view @tap="$util.goUrl( {url:`${detail.refund_code}`,openType:'copy'})"
							class="copy-btn sm flex-center fill-body" :style="{color:primaryColor}">复制</view>
					</view>
				</view>
			</block>
			<view class="flex-warp pt-md">
				<view class="text c-caption">下单时间</view>
				<view class="flex-1">{{detail.create_time}}</view>
			</view>
			<block v-if="detail.send_type == 2">
				<view class="flex-warp pt-md" v-if="detail.pay_time">
					<view class="text c-caption">支付时间</view>
					<view class="flex-1">{{detail.pay_time}}</view>
				</view>
				<view class="flex-warp pt-md">
					<view class="text c-caption">支付方式</view>
					<view class="flex-1">{{payType[detail.pay_model]}}</view>
				</view>
			</block>
		</view>
		<view class="order-text-info mt-md ml-md mr-md pd-lg fill-base f-caption c-title box-shadow radius-24"
			v-if="detail.pay_type == 7">
			<view class="flex-warp pt-sm" v-if="detail.hx_time">
				<view class="text c-caption">收货时间</view>
				<view class="flex-1">{{detail.hx_time}}</view>
			</view>
			<view class="flex-warp pt-md">
				<view class="text c-caption">收货人</view>
				<view class="flex-1">{{detail.hx_user_name}}</view>
			</view>
		</view>

		<view class="space-max-footer"></view>

		<view class="footer-btn fix fill-base pl-lg pr-lg" v-if="detail.pay_type!=7">
			<view class="flex-between">
				<view></view>
				<view @tap.stop="toTel" class="common-btn flex-center f-caption c-base radius ml-lg"
					:style="{background:primaryColor}">联系买家
				</view>
			</view>
			<view class="space-safe"></view>
		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				scrollTop: 0,
				options: {},
				detail: {},
				payType: {
					1: '微信支付',
					2: '余额支付',
					3: '支付宝支付'
				},
				statusType: {
					'-1': '已取消',
					1: '待支付',
					2: '待发货',
					3: '已发货',
					7: '已完成',
				},
				sendType: {
					1: '自提',
					2: '快递'
				},
				param: {
					page: 1,
				},
				list: {
					data: []
				},
				loading: true,
				popupInfo: {},
				lockTap: false,
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			configInfo: state => state.config.configInfo,
			userInfo: state => state.user.userInfo,
			haveOperItem: state => state.order.haveOperItem,
		}),
		onLoad(options) {
			this.options = options
			this.$util.showLoading()
			this.updateOrderItem({
				key: 'haveOperItem',
				val: false
			})
			this.initIndex()
		},
		onUnload() {
			if (!this.haveOperItem) return
			this.$util.back()
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		methods: {
			...mapActions(['getConfigInfo']),
			...mapMutations(['updateOrderItem']),
			async initIndex() {
				let {
					id,
				} = this.options
				let data = await this.$api.business.orderInfo({
					id
				})
				this.detail = data
				this.$util.hideAll()
			},
			initRefresh() {
				this.initIndex()
			},
			async toMap() {
				let {
					lat,
					lng,
					address
				} = this.detail
				await this.$util.checkAuth({
					type: 'userLocation'
				})
				await uni.getLocation({
					type: 'gcj02',
				})
				await uni.openLocation({
					latitude: lat * 1,
					longitude: lng * 1,
					name: address,
					scale: 28
				})
			},
			toTel() {
				let {
					mobile: url
				} = this.detail.address_info
				this.$util.goUrl({
					url,
					openType: 'call'
				})
			},
		}
	}
</script>


<style lang="scss">
	.business-order-detail {
		.order-seed-item {
			.seed-img {
				width: 80rpx;
				height: 80rpx;
				box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
			}
		}

		.item-video {
			width: 710rpx;
			height: 380rpx;
			display: block;
		}

		.footer-btn {
			width: 100%;
			bottom: 0;

			.flex-between {
				height: 98rpx;
			}
		}
	}
</style>
